package com.typhoon.service;

import com.typhoon.dao.UserDao;
import com.typhoon.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class UserService {

    private static final String DEMO_CACHE_NAME = "users";

    @Autowired
    private UserDao userDao;

    @Cacheable(value = DEMO_CACHE_NAME,key = "'user_' + #id")
    public List<User> findById(Long id) {
        log.info("UserService.findById query from DB;id={}",id);
        return this.userDao.findById(id);
    }

}
